package com.hax2max.view;

import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TabHost;

import com.hax2max.R;

public class TabHostController extends TabActivity{
	private TabHost mTabHost;
	private MenuViewController menuViewController;
	public static String[] actions = {
			ProfileViewController.actions[0],
			ProfileViewController.actions[1],
			ProfileViewController.actions[2],
			SettingsViewController.actions[0]
	};
	private Context _context;
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    _context = getBaseContext();
	    setContentView(R.layout.tabhost);
	    mTabHost = getTabHost();
	    Intent intent = getIntent();
	    String action = intent.getAction();
	    Intent profile = new Intent(actions[0],null,getBaseContext(),ProfileViewController.class);
	    Intent facebook = new Intent(actions[1],null,getBaseContext(),ProfileViewController.class);
	    Intent twitter = new Intent(actions[2],null,getBaseContext(),ProfileViewController.class);
	    Intent settings = new Intent(actions[3],null,getBaseContext(),SettingsViewController.class);

	    mTabHost.addTab(mTabHost.newTabSpec("profile").setIndicator("Profile").setContent(profile));
	    mTabHost.addTab(mTabHost.newTabSpec("facebook").setIndicator("Facebook").setContent(facebook));
	    mTabHost.addTab(mTabHost.newTabSpec("twitter").setIndicator("Twitter").setContent(twitter));
	    mTabHost.addTab(mTabHost.newTabSpec("settings").setIndicator("Settings").setContent(settings));
	    for(int i=0;i<actions.length;i++)
	    	if (action.equals(actions[i]))
	    		mTabHost.setCurrentTab(i);
	}
	
	 
    public boolean onCreateOptionsMenu(Menu menu) {
		
		MenuInflater inflater = getMenuInflater();
	    inflater.inflate(R.menu.menu, menu);
	    return true;
	}
	

    public boolean onOptionsItemSelected(MenuItem item){
	menuViewController.start(this,item);
	return true;
    }
    public void onResume(){
	if (menuViewController == null)
	    menuViewController = MenuViewController.getInstance(_context);
	super.onResume();
    }
}
